/**
=====================================================================================
 CNumEdit

 Description:
  An Edit-Control for Numbers
  Consists of a CButtonAutoRepeat for minus, a CButtonAutoRepeat for plus and
  a CEditKeyResponse for the Value

  Use SetValue and GetNumber to set/get the value.
  Use SetRange to set the min and max of a value

  HACK -> since this control is (here) only used inside another control
          it will send his messages to the parents parent and not to the parent
=====================================================================================
**/
#pragma once


#include "CButtonAutoRepeat.h"
#include "CEditKeyResponse.h"


class CNumEdit : public CWnd
{
        DECLARE_DYNAMIC(CNumEdit)

    public:
        CNumEdit();
        virtual ~CNumEdit();
        virtual BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);

        /**
         Set minimum and maximum value
        **/
        void SetRange(int min, int max);

        /**
         Set the Number
        **/
        void SetValue(int val);

        /**
         Set the Number without sending a message
         @return: true if changed
        **/
        virtual bool SetValueSilent(int val);

        /**
         Get the Number
        **/
        int  GetNumber() { return number;};

        void SetTextColor(COLORREF);
        void SetBackground(COLORREF);
        void SetColorsDefault();

        void    ShowRangeColors(bool b_show=true);



    protected:
        DECLARE_MESSAGE_MAP()

        /**
         Child Controlls
        **/
        CButtonAutoRepeat  button1;
        CButtonAutoRepeat  button2;
        CEditKeyResponse  edit;

        int   number; // the Number
        int   n_min;  // minimum
        int   n_max; // maximum

        /**
         to Handle WM_COMMAND messages from Childcontrolls
        **/
        virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);

        virtual void ShowNumber();
        virtual void OnChangeValue(int delta);
        virtual void OnEditLostFocus();

        BOOL   mb_only_num;

        bool            mb_show_range;

    private:
        COLORREF m_clrText;
        COLORREF m_clrBkgnd;
        CBrush  m_brBkgnd;

    public:
        /**
         Set focus to the Edit-Field (if recieving focus)
        **/
        afx_msg void OnSetFocus(CWnd* pOldWnd);

        /**
         On size change: recalc layout
        **/
        afx_msg void OnSize(UINT nType, int cx, int cy);
        afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
};


